package conf

import (
	"fmt"
	"io/ioutil"
	"os"
	"strings"
	tme "time"
)

type finfo struct {
	name string
	time int64
	path string
}

type JsonStruct struct {
}

func NewJsonStruct() *JsonStruct {
	return &JsonStruct{}
}

func (jst *JsonStruct) Load(filename string) string {
	//ReadFile函数会读取文件的全部内容，并将结果以[]byte类型返回
	data, err := ioutil.ReadFile(filename)
	if err != nil {
		fmt.Print(err)
	}
	if len(data) == 0 {
		return "false"
	}
	str := string(data[:])

	if err == nil {

		return str
	} else {

		return "false"
	}

}
func (jst *JsonStruct) Write(filename string, b string) {
	//ReadFile函数会读取文件的全部内容，并将结果以[]byte类型返回

	err := ioutil.WriteFile(filename, []byte(b), 0775)
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(-1)
	}

}
func Gtc(configname string, name string, time int64, path string) {
	if strings.Contains(configname, "/") {
		configname = strings.Replace(configname, "/", "_", -1)
	}
	JsonParse := NewJsonStruct()
	timestr := tme.Unix(time, 0).Format("2006-01-02 15:04:05")
	v := name + "\r\n" + timestr + "\r\n" + path
	JsonParse.Write("./"+configname+".txt", v)

}
func Gtcf(configname string) string {
	if strings.Contains(configname, "/") {
		configname = strings.Replace(configname, "/", "_", -1)
	}
	JsonParse := NewJsonStruct()
	fi := JsonParse.Load("./" + configname + ".txt")
	if fi != "false" {
		return fi
	} else {
		return "false"
	}

}

func main() {

}
